/** 
* 留言action类
* 
* @author  周郎(zhoulang),web@zhoulang.net
* @link http://www.zhoulang.net
* @version syuebook v1.0
* @Copyright 2009 syue.com, Inc. All rights reserved.
* @since   JDK1.6
*/  

package net.zhoulang.utility;

import java.util.Iterator;
import java.io.File;
import org.dom4j.io.SAXReader;
import org.dom4j.Document;
import org.dom4j.Element;
import org.apache.log4j.Logger;

/**
 * 管理员管理类
 * 
 * @author 周郎(zhoulang)
 *
 */
public class AdminUser {
	static Logger log = Logger.getLogger(AdminUser.class.getName());
	/**
	 * 判断用户是否登录
	 * 
	 * @param username
	 * @param userpwd
	 * @return boolean
	 */
	@SuppressWarnings("unchecked")
	public boolean getLogin(String username, String userpwd) {
		boolean isLogin = false;
		try {
			//取得用户存储的xml文档
			String filePath = this.getClass().getClassLoader().getResource("").getPath() + "adminuser.xml";
			//加载xml文档，并读取
			File file = new File(filePath);
			SAXReader sax = new SAXReader();
			Document doc = sax.read(file);
			Element element = doc.getRootElement();
			Iterator iter = element.elementIterator("User");
			//循环读取用户列表，并判断输入登录信息是否有效
			while(iter.hasNext()) {
				Element userElement = (Element)iter.next();
				if(userElement.attributeValue("name").equals(username) && userElement.attributeValue("pwd").equals(userpwd)) {
					isLogin = true;
					break;
				}
			}
		}
		catch(Exception e) {
			//错误信息写入日志
			log.error(e.toString());
		}
		return isLogin;
	}
}
